﻿using Games.Common;
using System;
using Xamarin.Forms;

namespace Games.Light
{
    class GameCell : BoxView
    {
        bool isBright;

        private Color Dark = Color.BurlyWood, Bright = Color.Chartreuse;
        public event EventHandler Tapped;

        public GameCell()
        {
            BackgroundColor = Dark;

            TapGestureRecognizer tapGesture = new TapGestureRecognizer { NumberOfTapsRequired = 1 };
            tapGesture.Tapped += (sender, args) =>
            {
                Tapped?.Invoke(this, EventArgs.Empty);
            };
            GestureRecognizers.Add(tapGesture);
        }

        public byte Col { set; get; }

        public byte Row { set; get; }

        public bool IsBright
        {
            set
            {
                if(isBright != value)
                {
                    isBright = value;
                    if(isBright)
                    {
                        this.ColorTo(this.BackgroundColor, Bright, c => this.BackgroundColor = c, 100, Easing.CubicIn);
                    }
                    else
                    {
                        this.ColorTo(this.BackgroundColor, Dark, c => this.BackgroundColor = c, 200, Easing.CubicOut);
                    }
                }
            }
            get
            {
                return isBright;
            }
        }
    }
}
